package org.lanyu.springainovel.chat.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.lanyu.springainovel.chat.service.ChatStreamService;
import org.lanyu.springainovel.chat.vo.QuestionVO;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

/**
 * AI聊天控制�? * 提供流式对话接口，支持指定模型回答、知识库检索、持久记忆、多模态、mcp工具调用
 */
@Slf4j
@Tag(name = "Ai聊天", description = "AI对话相关接口，支持指定模型回答、知识库检索、持久记忆、多模态、mcp工具调用")
@RestController
@RequestMapping("/chat")
@AllArgsConstructor
public class FluxChatController {

    private final ChatStreamService chatStreamService;

    @Operation(summary = "AI流式生成", description = "通过切换OllamaChatModel替换模型")
    @PostMapping(value = "/generateStream", produces = MediaType.TEXT_PLAIN_VALUE + ";charset=UTF-8")
    public Flux<String> generateStreamWithModel(@RequestBody QuestionVO body) {
        log.info("收到流式聊天请求，会话ID: {}, 模型ID: {}, 启用记忆: {}, 最大Token {}",
                body.getSessionId(), body.getModelId(), body.getMemory(), body.getMaxTokens());
        return chatStreamService.processStreamChat(body);
    }
}
